//
//  HeadLineCell.m
//  LuCoding
//
//  Created by lanou3g on 15/10/14.
//  Copyright © 2015年 自由科技. All rights reserved.
//

#import "HeadLineCell.h"
#import "HeadLineModel.h"

@implementation HeadLineCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setSubViews];
    }
    return self;
}

- (void)setSubViews {
    self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 100, 80)];
    [self addSubview:self.imgView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 5, self.frame.size.width-100, 25)];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    
    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 35, self.frame.size.width-100, 25)];
    self.descriptionLabel.font = [UIFont systemFontOfSize:12];
    self.descriptionLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.descriptionLabel];
    
    self.readCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 65, 100, 25)];
    self.readCountLabel.font = [UIFont systemFontOfSize:13];
    self.readCountLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.readCountLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 65, 100, 25)];
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    self.timeLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.timeLabel];
}

- (void)setCellModel:(HeadLineModel *)cellModel {
    self.titleLabel.text = cellModel.title;
    self.descriptionLabel.text = cellModel.content;
    self.readCountLabel.text = [NSString stringWithFormat:@"%@阅读量",cellModel.readCount];
    //时间戳：某个日期到1970年之间的一个差值
    NSInteger inter = [cellModel.time integerValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:inter];//参数为时间戳的大小
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MM月dd日 HH:mm"];
    NSString *str = [dateFormatter stringFromDate:date];
    self.timeLabel.text = str;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
